<div class="layui-form-item layui-form-text">
    <label class="layui-form-label">@if($must??true)<span style="color:red">*</span>@endif{{ $label??'图片' }}：</label>
    <div style="text-align: center;">
        <div alt="" class="upload" id="image_add">
            <div id="img_url" style="@if(!isset($val)||empty($val)) display: none;@endif">
                <input type="hidden" name="{{ $name??'img_url' }}" value="{{$val??''}}">
                <img src="{{ $val??'' }}" style=" max-height: 165px;max-width: 100%;" />
            </div>
            <div class="update-none" style="@if(isset($val)&&!empty($val)) display: none;@endif">
                <i class="iconfont icon-shangchuantupian1"></i>
                <p>点击添加图片</p>
            </div>
        </div>
        <div style="clear: both"></div>
    </div>
</div>

@section('js')
    @parent
    <script>
        layui.use('upload', function () {
            var upload = layui.upload;
            var $ = layui.$;

            //执行实例
            var uploadInst = upload.render({
                elem: '#image_add' //绑定元素
                , url: '/upload/image' //上传接口
                , done: function (res) {
                    //上传完毕回调
                    $('#img_url img').attr('src', res.data.src);
                    $('#img_url input[name={{ $name??'img_url' }}]').val(res.data.src);
                    $('#img_url').show();
                    $('#image_add .update-none').hide();
                }
                , error: function () {
                    //请求异常回调
                }
            });
        });
    </script>
@endsection